package com.ruoyi.web.controller.littleRedBook;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.littleRedBook.domain.pojo.User;
import com.ruoyi.littleRedBook.service.UserService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;


/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author
 * @since
 */
@RestController
@RequestMapping("/api/user")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 新增用户
     */
    @PostMapping
    public AjaxResult add(@RequestBody User user) {
        return AjaxResult.success(userService.save(user));
    }

    /**
     * 修改用户
     */
    @PutMapping
    public AjaxResult edit(@RequestBody User user) {
        return AjaxResult.success(userService.updateById(user));
    }

    /**
     * 删除用户
     */
    @DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable Long[] userIds) {
        return AjaxResult.success(userService.removeByIds(Arrays.asList(userIds)));
    }

    /**
     * 查询用户详情
     */
    @GetMapping("/{userId}")
    public AjaxResult getInfo(@PathVariable Long userId) {
        return AjaxResult.success(userService.getById(userId));
    }

    /**
     * 查询用户列表
     */
    @GetMapping("/list")
    public AjaxResult list() {
        return AjaxResult.success(userService.list());
    }
}
